package com.mhkj.base.rbac.permission.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mhkj.base.rbac.permission.entity.Permission;
import com.mhkj.base.rbac.permission.service.PermissionService;
import com.mhkj.base.region.service.NationService;
import com.mics.core.common.componet.Pagination;
import com.mics.core.common.componet.ResponseMessage;
import com.mics.core.system.base.controller.BaseController;
import com.mics.core.system.organizational.bean.Employee;
import com.mics.core.system.organizational.service.OrgService;
import com.mics.core.system.rbac.service.DictionaryService;

/**
 * 权限
 */

@Controller
@RequestMapping("/permission")
public class PermissionController extends BaseController<Permission> {
	@Autowired
	private PermissionService permissionService;
	@Autowired
	private NationService nationService;
	@Autowired
	private OrgService orgService;
	@Autowired
	private DictionaryService dictionaryService;
	/**
	 * 分页查询权限
	 * 
	 */
	@RequestMapping(value="/listByPage", method=RequestMethod.POST)
	@ResponseBody
	public Pagination<Permission> listByPage( Permission Permission, int pageIndex, int pageSize ) {
		Pagination<Permission> pagination = permissionService.listByPage(Permission,pageIndex, pageSize);
		
		List<Permission> data = pagination.getData();
		for (Permission ps : data) {
			String createBy = ps.getCreateBy();
			Employee employeeInfo = orgService.employeeInfo(createBy);
			ps.setCreatName(employeeInfo.getName());
		}
		
		return pagination;
	}

	/**
	 * 保存
	 * 
	 */
	@RequestMapping(value="/save", method=RequestMethod.POST)
	@ResponseBody
	public ResponseMessage save(Permission Permission) {
		
		
		String message = permissionService.save(Permission);
		return ResponseMessage.createMessage("ok".equals(message), message);
	}

	/**
	 * 修改
	 * 
	 */
	@RequestMapping(value="/edit", method=RequestMethod.POST)
	@ResponseBody
	public ResponseMessage edit(Permission Permission) {
		String message = permissionService.edit(Permission);
		return ResponseMessage.createMessage("ok".equals(message), message);
	}

	/**
	 * 删除
	 * 
	 */
	@ResponseBody
	public ResponseMessage del(Long id) {
		Permission Permission = new Permission();
		Permission.setId(id);
		String message = permissionService.del(Permission);
		return ResponseMessage.createMessage("ok".equals(message), message);
	}

	/**
	 * 查询所有权限
	 * 
	 */
	@RequestMapping(value="/list", method=RequestMethod.POST)
	@ResponseBody
	public List<Permission> listAll() {
		
		List<Permission> list = permissionService.findAll();
		return list;
	}
	
	/**
	 * 查询权限信息
	 */
	@RequestMapping(value="/info", method=RequestMethod.POST)
	@ResponseBody
	public Permission info(@RequestParam(value = "id", required = true) long id) {
		Permission Permission = permissionService.getById(id);
		return Permission;
	}



}
